<?php
class User extends CActiveRecord
{
        public $password;
        public $password_repeat;
        public $verifyCode;
        public $thumb;
        public $avatar_medium;
        public $avatar_small;
        
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function tableName()
	{
		return 'user';
	}

	public function rules()
	{
		return array(
			array('username,email', 'required'),
			array('username', 'length', 'max'=>20),
			array('password, email', 'length', 'max'=>255),
                        array('email', 'email'),
                        array('password','compare','on'=>'create'),
                        array('password_repeat,verifyCode,thumb,avatar_large,avatar_medium,avatar_small','safe'),
                        array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
			array('id, username, password, email', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
		);
	}

	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'username' => 'Username',
			'password' => 'Password',
                        'password_repeat'=>'Password Repeat',
			'email' => 'Email',
                        'verifyCode'=>'Verification Code',
                        'avatar_large'=>'Avatar',
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('email',$this->email,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}